<link rel="stylesheet" type="text/css" href="/Static/mobile/css/charge.css">
<style>
.zhuan {
  padding: 8px 10px 0 10px;
  margin:7px 0;
}

.block-item{
	margin:10px 0;
}

/*
 * 清除ios自带样式
 */
input,textarea{
	-webkit-appearance:none;
}

.zhuan input {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;	
  width: 100%;
  height: 40px;
  padding: 8px;
  line-height: 22px;
  color: #333;
  border: 1px solid #e5e5e5;
  border-radius : 0px ;
}
</style>
<style>
 <?php if(!$is_mobile){ ?>}
    html, body {
    height: 100%;
    width: 50%;
    margin: 0 auto;
}
<?php } ?>
</style>


	<div class="content free-cash" style="margin-bottom:100px;">
		<div class="cashier-info-container center">
			<div class="avatar cashier-avatar">
				<img class="circular" src="<?php echo $memberinfo['headimgurl'];?>" id="headimgurl" onerror="javascript:this.src='__STATIC__mobile/images/userimg.png';">
			</div>
			
			<div>
				<p class="center  font-size-12" style="margin:0px 0px 15px 0px;" id="nickname"><?php echo $memberinfo['realname'] ? $memberinfo['realname'] : $memberinfo['nickname'];?></p>
			
			</div>
			
<div class="zhuan">
	<input value="我的可转<?php echo C('YONGJIN_NAME');?>: <?php echo $memberinfo['money'];?>" disabled>
</div>
				
<div class="zhuan">
	<input type="tel" maxlength="11"  id="to_uid" placeholder="(必填)*对方账户编码ID或对方手机账户">
	<input type="hidden" maxlength="11" name="to_uid" id="realuid">
	<input type="hidden" value="" id="history_uid">
</div>
		
<div class="zhuan" style="display:none" id="nickname_tap">
	<input value="" readonly id="nickname2">
	
</div>

<div class="js-cashier-form block cashier-form text-left">
	<label for="cashier-price" class="font-size-12 cashier-label">转账<?php echo C('YONGJIN_NAME');?>（元）:</label>
	<p class="cashier-field">
		<i class="money-text">¥</i><input maxlength="8" id="cashier-price" name="money" type="number" class="cashier-text">
	</p>
</div>

<div class="zhuan">
	<input placeholder="(选填) 对方手机号码" type="tel" maxlength="11" name="to_mobile" id="to_mobile">
</div>

<div class="zhuan">
	<input placeholder="(选填) 留言备注" type="text" maxlength="20" name="message" id="message">
</div>
			
			
		</div>
		<div class="action-container" id="js-cashier-action">
			<div style="margin-bottom: 10px;">
				<?php if($memberinfo['money']>0){ ?>
				<button type="button" id="zhuanzhang" class="btn-pay btn btn-block btn-large btn-wxwappay  btn-green">下一步</button>
				<?php }else{ ?>
				<button type="button" style="background-color: #e5e5e5;" class="btn-pay btn btn-block btn-large">你的可转余额不足</button>
				<?php } ?>
			
			</div>
			<div style="margin-bottom: 10px;">

			</div>
		</div>
		<div class="center action-tip js-cashier-tip">请仔细核对转账信息,以免造成财产损失</div>
	</div>
	
<script type="text/javascript">
$(function(){
	
	//绑定点击事件函数 
	$("#zhuanzhang").click(function(){
		zhuanzhang();
	}); 
	
	$('#to_uid').change(function() {
		//判断当前账号是否正确
		var to_uid = $(this).val();
		ajaxUid(to_uid);

	});
	
	$('#cashier-price').change(function() {
		//判断当前账号是否正确
		var mymoney = "<?php echo $memberinfo['money'];?>";
		mymoney = parseFloat(mymoney);

		var money = $(this).val();
		money = parseFloat(money);
		
		if(money<=0){
			showerror("转账金额必须大于0");
			return false;
		}
		if(money>50000){
			showerror("转账金额不能大于5万");
			return false;
		}
		
		if(money>mymoney){
			showerror("您的可转余额为"+mymoney+",不足够本次转账,请修改转账金额");
			//$(this).val('');
			return false;
		}
		
	});
	
	
}); 
	
function ajaxUid(to_uid){
	var url = "/mobile/transfersmoney/getfriendajax/?uid="+to_uid;
	$.ajax({
		url : url,
		type : "GET",
		dataType : 'json',
		success : function(data) {
			//关闭正在加载
			 layer.closeAll();//关闭所有
			if(data.url){
				var urls = data.url;
			}else{
				var urls = '';
			}

			if(data.ret == 0){
				// 成功
				if(data.data.realname){
					var nickname = data.data.realname;
				}else{
					var nickname = data.data.nickname;
				}
				
				$("#realuid").val(data.data.uid);
				$("#headimgurl").attr("src",data.data.headimgurl);
				$("#nickname").html(nickname);
				$("#nickname2").val("对方昵称:"+nickname);
				
				$("#nickname_tap").show();
				
			}else{
				// 失败
				showerror(data.msg,urls);
				$("#to_uid")[0].focus();
				$("#nickname_tap").hide();
				
				$("#realuid").val('');
				$("#headimgurl").attr("src",'');
				$("#nickname").html('');
				$("#nickname2").val("对方昵称:");
				
			}
		},
		beforeSend:function(){
			//正在加载
			layer.open({
		        type: 2,
		        shade: true,
		        shadeClose: false,
		    });
			
       },
       error: function() {
		   //关闭正在加载
    	   layer.closeAll();//关闭所有
		   showerror("网络错误,请重试");
       }
       
	});
}

function zhuanzhang(){
	
	var to_uid = $("#realuid").val();
	if(!to_uid){
		showerror("请检查对方的 会员编号ID 或 手机账户 是否输入正确");
		return false;
	}
	
	var mymoney = "<?php echo $memberinfo['money'];?>";
	mymoney = parseFloat(mymoney);
	
	var money = $("#cashier-price").val();
	money = parseFloat(money);
	
	if(!checkCurrency(money)){
		showerror("转账金额有误");
		return false;
	}
	
	if(money<=0){
		showerror("转账金额必须大于0");
		return false;
	}
	
	if(money>mymoney){
		showerror("您的余额为"+mymoney+",不足够本次转账,请修改转账金额");
		//$(this).val('');
		return false;
	}
	
	var to_mobile = $("#to_mobile").val();
	if(to_mobile){
		if(!isMobile(to_mobile)){
			showerror("对方手机号填写错误,请更改");
			return false;
		}
	}
	
	var message = $("#message").val();
	
	var history_uid = $("#history_uid").val();
	
	if(history_uid == to_uid){

	    layer.open({
	        content: "你刚已经给"+$("#nickname").html()+"进行了一笔转账,你确定还要继续转账吗?",
	        btn: ['确定转账', '取消'],
	        yes: function(index){
	        	suretf(to_uid,money,to_mobile,message);
	        	return false;
	        },
	        no: function(index){
	            layer.close(index);
	            return false;//终止操作
	        }
	    });
	    
	}else{
		suretf(to_uid,money,to_mobile,message);//确认转账
	}


}


function suretf(to_uid,money,to_mobile,message){
	
	var title = "你正在给:"+$("#nickname").html()+"(<em style='color:red;'>编号ID:"+to_uid+"</em>)转账<em style='color:red;'>"+money+"元</em>,你确定要进行此次转账吗?";
	
    layer.open({
        content: title,
        btn: ['确定转账', '取消'],
        yes: function(index){
        	
        	$("#history_uid").val(to_uid);//写入转账历史
        	
        	tfmoney(money,to_uid,to_mobile,message);
            layer.close(index);
        }
    });
}

/*
 * 转账
 */
function tfmoney(money,to_uid,to_mobile,message){
	
	
	$.ajax({
		url : '/mobile/transfersmoney/tfmoneyajax',
		type : 'post',
		data : {'money':money,'to_uid':to_uid,"to_mobile":to_mobile,"message":message},
		dataType : 'json',
		success : function(data) {
			//关闭正在加载
			layer.closeAll();//关闭所有
			
			if(data.url){
				var urls = data.url;
			}else{
				var urls = '';
			}

			if(data.ret == 0){
				// 成功
				showsuccess(data.msg,urls);
				
			}else{
				// 失败
				showerror(data.msg,urls);
			}
		},
		beforeSend:function(){
			//正在加载
			layer.open({
		        type: 2,
		        shade: true,
		        shadeClose: false,
		    });
			
       },
       error: function() {
		   //关闭正在加载
    	   layer.closeAll();//关闭所有
		   showerror("网络错误,请重试");
       }
       
	});
}
</script>
<include file="Common:nav" />